package cms.bojx.com.cglib.test;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class CglibProxy implements MethodInterceptor {
	private Enhancer enhance=new Enhancer();
	@SuppressWarnings("rawtypes")
	public Object getProxy( Class clazz){
		enhance.setSuperclass(clazz);
		enhance.setCallback(this);
		return enhance.create();
	}
	@Override
	public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
		System.out.println("前置代理");
		Object result=proxy.invokeSuper(obj, args);
		System.out.println("后置代理");
		return result;
	}

}
